package com.ssy.lingxi.member.merchant.controller.web;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.bo.ManageLoginBO;
import com.ssy.lingxi.member.merchant.model.bo.WebLoginBO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.*;
import com.ssy.lingxi.member.merchant.model.vo.login.response.CaptchaPicVO;
import com.ssy.lingxi.member.merchant.model.vo.login.response.MemberAuthCodeVO;
import com.ssy.lingxi.member.merchant.service.web.IMemberLoginService;
import org.springframework.http.HttpHeaders;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @menu 业务中台、平台后台 -- 用户登录接口
 * @author 万宁
 * @version 2.0.0
 * @date 2020-06-05
 */
@RestController
@RequestMapping("/member")
public class MemberLoginController {

    @Resource
    private IMemberLoginService loginService;

    /**
     * 业务平台 - 账号或手机号登录
     * @param headers HttpHeaders信息
     * @param loginVO 接口参数
     * @return 登录结果
     */
    @RequestMapping("/login")
    public Wrapper<WebLoginBO> accountOrPhoneLogin(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberLoginVO loginVO) {
        return loginService.accountOrPhoneLogin(headers, loginVO);
    }

    /**
     * 业务平台 - 切换登录用户的会员角色
     * @param headers HttpHeaders信息
     * @param roleVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/login/switchrole")
    public Wrapper<WebLoginBO> switchMemberRole(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberLoginSwitchMemberRoleVO roleVO) {
        return loginService.switchMemberRole(headers, roleVO);
    }

    /**
     * 业务平台 - 重新获取登录返回信息接口
     * @param headers HttpHeaders信息
     * @return 操作结果
     */
    @RequestMapping(value = "/login/reget", method = RequestMethod.GET)
    public Wrapper<WebLoginBO> loginBusinessPlatformWithToken(@RequestHeader HttpHeaders headers) {
        return loginService.loginBusinessPlatformWithToken(headers);
    }

    /**
     * 平台后台 - 账号登录
     * @param headers HttpHeaders信息
     * @param loginVO 接口参数
     * @return 登录结果
     */
    @RequestMapping(value = "/manage/login", method = RequestMethod.POST)
    public Wrapper<ManageLoginBO> manageAccountOrPhoneLogin(@RequestHeader HttpHeaders headers, @RequestBody @Valid ManageLoginVO loginVO) {
        return loginService.manageAccountOrPhoneLogin(headers, loginVO);
    }

    /**
     * 平台后台 - 重新获取登录返回信息接口
     * @param headers HttpHeaders信息
     * @return 操作结果
     */
    @RequestMapping(value = "/manage/login/reget", method = RequestMethod.GET)
    public Wrapper<ManageLoginBO> loginManagePlatformWithToken(@RequestHeader HttpHeaders headers) {
        return loginService.loginManagePlatformWithToken(headers);
    }

    /**
     * 业务平台 - 获取登录授权链接
     * @param headers HttpHeaders信息
     * @return 授权码
     */
    @RequestMapping("/login/authUrl")
    public Wrapper<MemberAuthCodeVO> getAuthLoginUrl(@RequestHeader HttpHeaders headers) {
        return loginService.getAuthLoginUrl(headers);
    }

    /**
     * 业务平台 - 验证扫码登录(轮询)
     * @param headers HttpHeaders信息
     * @param memberAuthCodeVO 接口参数
     * @return 返回结果
     */
    @RequestMapping(value = "/loginInfo", method = RequestMethod.POST)
    public Wrapper<WebLoginBO> loginInfo(@RequestHeader HttpHeaders headers, @RequestBody @Validated ActivityMemberAuthCodeVO memberAuthCodeVO) {
        return loginService.getAuthCodeLoginInfo(headers, memberAuthCodeVO);
    }

    /**
     * 获取滑块验证码
     * @param headers HttpHeaders信息
     * @param captchaVO 接口参数
     * @return 验证码信息
     */
    @RequestMapping(value = "/captcha", method = RequestMethod.GET)
    public Wrapper<CaptchaPicVO> captcha(@RequestHeader HttpHeaders headers, @Valid CaptchaVO captchaVO) {
        return loginService.captcha(headers, captchaVO);
    }
}
